#include "common.h"
#include "pathconst.h"

#include <QFile>
#include <QDomDocument>

std::string g_ServerIp;
unsigned short g_ServerPort = 1114;
unsigned short g_DataServerPort = 1101;
unsigned short g_GroupFileServerPort;
unsigned short g_FileBrowserPort = 1121;
unsigned short g_FileBrowserTransferPort = 1512;

Scheduler *g_PlayScheduler;
Scheduler *g_VolumeScheduler;

QThread* g_MainThread;
int g_MainWindowNo = 1;
int g_TimeWindowNo = 2;
int g_SlaveWindowNo = 3;
int g_TextWindowNo = 4;

bool g_IsOnline = false;
CommandChannel *g_CommandChannel = NULL;

unsigned long g_PlayListId = 0;

QTimer* g_RealTimeStopTimer = new QTimer;

ReceiveAndPlayAd* g_RealTimeVideoReceiveAndPlay;
ReceiveAndPlayAd* g_RealTimeAudioReceiveAndPlay;

QString g_LocalVideoTagName = "FileList";
QString g_LocalTextTagName = "LocalText";
QString g_LocalTimeTagName = "LocalTime";

QString g_LocalTextAttribute = "Content";

int GetClientId()
{
	QFile informationFile(g_InformationFileName);
	if(!informationFile.exists())
	{
		return -1;
	}
	QDomDocument informationXml;
	informationXml.setContent(&informationFile);
	QString idStr = informationXml.firstChildElement("ClientInfo").attribute("Id");
	bool isSucc;
	int clientId = idStr.toInt(&isSucc);
	if(!isSucc)
	{
		return -1;
	}
	return clientId;
}

#include <QObject>
#include <QDebug>

void ErrorPrint(const QString& errorMsg)
{
	qDebug()<<errorMsg;
}

void ErrorPrint(const std::string& errorMsg)
{
	ErrorPrint(QString(errorMsg.c_str()));
}

void Print(const std::string& errorMsg)
{
	ErrorPrint(errorMsg);
}

void Print(const QString& errorMsg)
{
	ErrorPrint(errorMsg);
}

void SetString(const QString& source, QString* des)
{
	if(des == NULL)
		return;
	else
		*des = source;
}

QString tr( const char * sourceText, const char * disambiguation, int n)
{
	return QObject::tr(sourceText, disambiguation, n);
}

